package com.QRcodeBuilder;

import java.util.Date;
import java.util.HashMap;

import com.util.Log4gUtil;
import com.util.RandomUtil;

public class CreateQr {
	public String sessionid;
	public String text="无效字符串";
	
	
	/**
	 * 
	 * 生成app授权二维码内容
	 * @param userid
	 * @param ip
	 * @param mac
	 * @param nickname
	 * @param phone
	 * @param siteAreaid
	 * @return
	 */
	public boolean createNetQr(int userid,String ip, String mac,String nickname,String phone,int siteAreaid,String headimg){
		boolean fig = false;
		if(userid!=0&&ip!=null&&phone!=null&&siteAreaid!=0&&!ip.equals("")&&!phone.equals("")){
			long time = new Date().getTime();
			sessionid = time+""+userid+"";
			Log4gUtil.getLog().info("createNetQr-userid:"+userid+"-sessionid:"+sessionid);
			NetQrVo netQrVo = NetQrVo.getNetQrVo();
			HashMap<String, NetQrEntity> netQrEntityMap = netQrVo.getNetQrEntityMap();
			NetQrEntity netQrEntity= netQrEntityMap.get(sessionid);
			if(netQrEntity==null){
				netQrEntity = new NetQrEntity(sessionid, 0, "",ip,mac,phone,siteAreaid,userid,nickname,headimg);
				netQrEntityMap.put(sessionid, netQrEntity);
			}else{
				netQrEntityMap.remove(sessionid);
				netQrEntity = new NetQrEntity(sessionid, 0, "",ip,mac,phone,siteAreaid,userid,nickname,headimg);
				netQrEntityMap.put(sessionid, netQrEntity);
			}
			text ="{\"from\":\"Altair\",\"for\":\"appAccreditNet\",\"sessionid\":\""+sessionid+"\"}";
			 fig = true;
		}
		return fig;
	}
	
	/**
	 * 生成pc授权二维码内容
	 * @param ip
	 * @param mac
	 * @param siteAreaid 区域
	 * 
	 */
	public boolean createPCNetQr(String ip,String mac,int siteAreaid,String show,String qrType){
		boolean judge = false;
			if(ip!=null&&!ip.equals("")&&mac!=null&&!mac.equals("")&&siteAreaid!=0){
				long time = new Date().getTime();
				//生成二维码Id
				sessionid = time+""+RandomUtil.getRandomShuzi(4)+siteAreaid;
				//二维码内容
				if(qrType==null)
					qrType = "";
				
				if(qrType.equals("QR0002"))
					text ="{\"from\":\"Altair\",\"for\":\"pcAccreditNet2\",\"sessionid\":\""+sessionid+"\"}";
				else
					text ="{\"from\":\"Altair\",\"for\":\"pcAccreditNet\",\"sessionid\":\""+sessionid+"\"}";
				
				
				Log4gUtil.getLog().info("createNetPCQr--sessionid:"+sessionid);
				//调出缓存
				NetQrVo netQrVo = NetQrVo.getNetQrVo();
				HashMap<String, NetQrPCEntity> pcMap = netQrVo.getNetQrPCEntityMap();
				//创建缓存内容
				NetQrPCEntity pcEntity = new NetQrPCEntity(ip, mac, siteAreaid,  show,"",0);
				//加入缓存
				pcMap.put(sessionid, pcEntity);
				judge = true;
			}
			return judge;
	}
}
